#define _CRT_SECURE_NO_WARNINGS 1
#include "SqList.h"

void InitSqList(SL* ps) {
	ps->arr = NULL;
	ps->size = 0;
	ps->capacity = 0;
}

void SLPrint(SL* ps) {
	for (int i = 0; i < ps->size; i++)
	{
		printf("%d ", ps->arr[i]);
	}
	printf("\n");
}

void SLCapacityCheck(SL* ps) {
	if (ps->capacity == ps->size) {
		int NewCapacity = ps->capacity == 0 ? 4 : 2 * ps->capacity;
		SLDataType* ptemp = (SLDataType*)realloc(ps->arr, NewCapacity);
		if (!ptemp) {
			perror("realloc");
			exit(1);
		}
		ps->arr = ptemp;
	}
}

void SLPushBack(SL* ps, SLDataType x){
	assert(ps);
	SLCapacityCheck(ps);
	ps->arr[ps->size++] = x;
}